package json2objerror;

import untils.JsonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chaird
 * @create 2022-04-17 13:11
 */
public class MainError {

  public static void main(String[] args) {
    FdcpRes res = buildRes();
    // 创建JSON字符串
    String s = JsonUtils.objectToJson(res);
    FdcpRes fdcpRes = JsonUtils.jsonToPojo(s, FdcpRes.class);
    List<Ecodata> data = (List<Ecodata>) fdcpRes.getData();
    for (Ecodata datum : data) {
      System.out.println(datum);
    }
  }

  public static FdcpRes buildRes(){
    // 创建两个对象
    List<Ecodata> ecodataList = new ArrayList<>();
    Ecodata e1 = new Ecodata();
    e1.setId(1);
    e1.setValue(1D);
    ecodataList.add(e1);
    Ecodata e2 = new Ecodata();
    e2.setId(2);
    e2.setValue(2D);
    ecodataList.add(e2);
    // 封装结果
    FdcpRes res = new FdcpRes();
    res.setCode(200);
    res.setData(ecodataList);
    return res;
  }
}
